import { instance } from '../request'

const request1 = instance

/**
 * 注册账号
 * @param account  账号
 * @param password 密码
 * */
export const registerAccountApi = (
  account: string,
  password: string
): PromiseRes =>
  request1.post(`/api/register`, {
    account,
    password,
  })

/**
 * 账号登录
 * @param account  账号
 * @param password 密码
 * */
export const loginAccountApi = (
  account: string,
  password: string
): PromiseRes =>
  request1.post(`/api/login`, {
    account,
    password,
  })

/**
 * 获取登录用户信息
 * @returns
 */
export const getUserInfoApi = (): PromiseRes<masterInfoItf> =>
  request1.get(`/user/masterInfo`)

/**
 * 修改用户信息
 * @param nickname 昵称
 * @returns
 */
export const modifyUserInfoApi = (nickname: string): PromiseRes =>
  request1.post(`/user/modifyInfo`, {
    nickname,
  })

/**
 * 更新头像
 * 添加一个新的表单字段，使用“file”作为键，选择一个要上传的文件。
 * let formdata = new FormData()
 * formdata.append('file', $file)
 * */
export const updateAvatarApi = (formdata): PromiseRes =>
  request1.post(`/user/avatar`, formdata, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  })
